<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        button{
            width: 30px;
            padding: 0 10px;
            margin: 0 5px;
        }
    </style>
</head>

<body>
    <div id="app">
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
    </div>

    <template id="cpn">
        <div>
            <h2>当前计数: {{counter}}</h2>
            <button @click='decrement' :disabled = 'counter <= 0'>-</button>
            <button @click='increment' :disabled = 'counter >= 10'>+</button>
        </div>
    </template>

    <script src='../js/vue.js'></script>
    <script>
        Vue.component('cpn', {
            template: '#cpn',
            //data必须为函数，不能为对象， 思路:组件需要复用，都单独有自己的逻辑，不能起连锁反应 
            data() {
                return {
                    counter: 0
                }
            },
            methods:{
                decrement() {
                    this.counter--;
                },
                increment() {
                    this.counter++;
                }
            }
        })

        const app = new Vue({
            el: '#app',
            data: {

            },
            methods: {

            }
        })
    </script>
</body>

</html>